<?php
/*=============================================*/
/* manage_workers.php                         */
/* ------------------------------------------- */
/* modifies workers, receives input           */
/* via POST or GET from                        */
/* workers.php                                */
/*=============================================*/

require_once('include_functions.php');


switch($_POST['action']) {
	case "create":
	// create new user
		// clean all vars for sql submission
		$workerName = clean($_POST['workerName']);
		$workerEmail = clean($_POST['workerEmail']);

		$sql =	"INSERT INTO `workers` SET ".
				"workerName = '". $workerName ."', ".
				"workerEmail = '". $workerEmail ."';":

		echo $sql;
		// readd once we figure out the issue with dbms error?
		//if($result = mysql_query($sql)) showerror($result); 
		if($result = mysql_query($sql)) echo mysql_error(); 
		break;

	case "edit":
	// edit existing user
		// clean all vars for sql submission
		$workerId = clean($_POST['workerId']);
		$workerName = clean($_POST['workerName']);
		$workerEmail = clean($_POST['workerEmail']);

		$sql =	"UPDATE `workers` SET ".
				"workerName = '". $workerName ."', ".
				"workerEmail = '". $workerEmail ."', ".
				"WHERE workerId = '" $workerId ."';"

		echo $sql;
		// readd once we figure out the issue with dbms error?
		//if($result = mysql_query($sql)) showerror($result); 
		if($result = mysql_query($sql)) echo mysql_error(); 
		break;

	case "delete":
	// delete an existing worker
		// clean vars for sql submission
		$workerId = clean($_POST['workerId']);
		
		$sql =	"DELETE FROM `workers` ".
				"WHERE workerId = '". $workerId ."';";

		// readd once we figure out the issue with dbms error?
		//if($result = mysql_query($sql)) showerror($result); 
		if($result = mysql_query($sql)) echo mysql_error(); 
		break;

	default:
	// send user back to homepage
		break;
}

?>
